package com.art.sunflower.controller;

import com.art.sunflower.enumeration.CourseStatusType;
import com.art.sunflower.service.CourseService;
import com.art.sunflower.util.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping(value = "courseByAdmin")
@Api(value = "课程管理控制器")
public class CourseByAdminController {
    @Resource
    CourseService courseService;

    @ResponseBody
    @RequiresRoles(value = {"admin"})
    @PutMapping("pssStatus")
    @ApiOperation("修改课程状态")
    public Message updateCourseStatuByAdmin(int id, CourseStatusType statu) {
        if (courseService.updateCourseStatu(id, statu) == 1) {
            return Message.createSuc("修改成功");//修改成功
        }
        return Message.createErr("修改失败");//添加失败
    }

    @ResponseBody
    @RequiresRoles(value = {"admin"})
    @PutMapping("status")
    @ApiOperation("课程审定")
    public Message CourseStatuCheck(@RequestParam("id") int id, @RequestParam("teach_fee") int teachFee, @RequestParam("material_fee") int materialFee, @RequestParam("statu") CourseStatusType statu) {
        if (courseService.courseStatuCheck(id, teachFee, materialFee, statu) == 1) {
            return Message.createSuc("审定成功");//审定成功
        }
        return Message.createErr("审定失败");//审定失败
    }

    @ResponseBody
    @RequiresRoles(value = {"admin"})
    @GetMapping("unApproved")
    @ApiOperation("分页获取未审定课程信息列表")
    public Message findAllCourseByAdmin(@RequestParam Integer pagenum, @RequestParam Integer pagesize) {
        return Message.createSuc(courseService.findAllCourseByAdmin(pagenum, pagesize));
    }

    @ResponseBody
    @RequiresRoles(value = {"admin"})
    @GetMapping("approved")
    @ApiOperation("分页获取已审定课程信息列表")
    public Message findAllCourseByAdmin2(@RequestParam Integer pagenum, @RequestParam Integer pagesize) {
        return Message.createSuc(courseService.findAllCourseByAdmin2(pagenum, pagesize));
    }

    @ResponseBody
    @RequiresRoles(value = {"admin"})
    @GetMapping("{id}")
    @ApiOperation("获取一个课程信息列表")
    public Message findOneCourseByAdmin(@PathVariable int id) {
        return Message.createSuc(courseService.findOneCourseByAdmin(id));
    }


}